/*
 * Lighting
 * CSCI 4229/5229 Assignment 7
 *
 * Brent Smith <brent.m.smith@colorado.edu>
 *
The full set of keybindings are available as below:

 Orientation/Viewing Angle/Zoom/Projection:
  Left/h    - Rotate the image counter-clockwise around the Y-axis
  Right/l   - Rotate the image clockwise around the Y-axis
  Up/k      - Rotate the image around the X-axis
  Down/j    - Rotate the image around the X-axis
  Home      - Set the orientation around X/Y axes to zero degrees
  Page Up   - Zoom in by decreasing dimension of world
  Page Down - Zoom out by increasing dimension of world
  + (plus)  - Zoom in by increasing field of view angle
  - (minus) - Zoom out by decreasing field of view angle

 General:
  e         - Toggle display of global state variables
  m         - Toggle between different modes
              0 = Orthogonal projection
              1 = Perspective projection
              2 = Perspective projection w/ fps style camera
  f         - Toggle between fan speeds 0, 1, 2 and 3
  x         - Toggle display of x, y and z axes
  Space     - Toggle display of this help screen
  Esc       - Exit the application.

 FPS Mode:
  w         - Move the player forward
  s         - Move the player backward
  a         - Make the player look to the left
  d         - Make the player look to the right
  z         - Reset player position\n"
  Mouse     - Change viewing angle and pitch (up/down)

 Lighting:
  1         - Toggle all lighting on/off
  2         - Toggle lamp on/off
  u/U       - Turn up/down ambient component of rotating light
  i/I       - Turn up/down diffuse component of rotating light
  o/O       - Turn up/down specular component of rotating light
 */

#include <vector>
#include <iterator>

#include <cstdio>
#include <cmath>    /* needed for sqrt(), pow(), fmod() */
#include <cassert>  /* needed for, surprise, assert() */
#include <cstdlib>  /* needed for exit() */
#include <cstdarg>  /* for va_list, etc.. */
#include <cstring>  /* for strcmp(), etc.. */

/* SDL headers */
#include "SDL.h"
#include "SDL_opengl.h"

#include "common.h"
#include "DrumApp.h"
#include "ConfigManager.h"
#include "LogUtil.h"

using namespace std;
using namespace csci5229;

///////////////////////////////////////////////////////////////////
// Static Function definitions
///////////////////////////////////////////////////////////////////
static LogLevel parseLogLevel (const char *loglevel)
{
    if (strcasecmp(loglevel,"DEBUG")==0)
        return LEVEL_DEBUG;
    else if (strcasecmp(loglevel,"INFO")==0)
        return LEVEL_INFO;
    else if (strcasecmp(loglevel,"WARN")==0)
        return LEVEL_WARN;
    else if (strcasecmp(loglevel,"ERROR")==0)
        return LEVEL_ERROR;
    else if (strcasecmp(loglevel,"FATAL")==0)
        return LEVEL_FATAL;
    else
        // default level is INFO
        return LEVEL_INFO;
}

///////////////////////////////////////////////////////////////////
// External Function definitions
///////////////////////////////////////////////////////////////////

/**
 * main entry point to application.
 */
int main (int argc, char *argv[])
{
    DrumApp app("Final Project (HW9) - Brent Smith");

    ConfigManager& manager = ConfigManager::getInstance();
    manager.loadPropertiesFromFile ("config.cfg");

    // Set Logging level
    LogLevel level = 
        parseLogLevel(manager.getProperty("LogLevel", "INFO"));
    LogUtil::SetLevel(level);
    if (LogUtil::Level() == LEVEL_DEBUG)
        manager.listProperties();

    bool fullscreen = 
        strcmp(manager.getProperty("Fullscreen", "false"), "true") == 0;
    app.setFullscreen(fullscreen);

    bool fsaa = 
        strcmp(manager.getProperty("EnableFSAA", "false"), "true") == 0;
    app.setFSAA(fsaa);

    const char *samples = manager.getProperty("SamplesFSAA", "2");
    app.setSamplesFSAA((int)atoi(samples));

// hack for windows to get printf to work for stdout/stderr.
#ifdef _WIN32
    const char * confile = "CONOUT$";

    FreeConsole();
    if(  !AllocConsole() )
    {
        // handle error
    }

    freopen(confile, "w", stdout);
    freopen(confile, "w", stderr);
#endif

    app.InitApp();
    app.Start();
 
    return 0;
}

/* vim: set tabstop=4 shiftwidth=4 softtabstop=4: */
